/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.gog.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thinkgem.jeesite.modules.test.entity.Test;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.gog.entity.TestGoods;
import com.thinkgem.jeesite.modules.gog.service.TestGoodsService;

/**
 * 商品测试Controller
 * @author dby
 * @version 2020-09-01
 */
@Controller
@RequestMapping(value = "${adminPath}/gog/testGoods")
public class TestGoodsController extends BaseController {

	@Autowired
	private TestGoodsService testGoodsService;

	@ModelAttribute
	public TestGoods get(@RequestParam(required=false) String id) {
		TestGoods entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = testGoodsService.get(id);
		}
		if (entity == null){
			entity = new TestGoods();
		}
		return entity;
	}
	@RequiresPermissions("gog:testGoods:view")
	@RequestMapping(value = {"list", ""})
	public String list(TestGoods testGoods, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TestGoods> page = testGoodsService.findPage(new Page<TestGoods>(request, response), testGoods);
		model.addAttribute("page", page);
		return "modules/gog/testGoodsList";
	}

	@RequiresPermissions("gog:testGoods:view")
	@RequestMapping(value = "form")
	public String form(TestGoods testGoods, Model model) {
		model.addAttribute("testGoods", testGoods);
		return "modules/gog/testGoodsForm";
	}

	@RequiresPermissions("gog:testGoods:edit")
	@RequestMapping(value = "save")
	public String save(TestGoods testGoods, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, testGoods)){
			return form(testGoods, model);
		}
		testGoodsService.save(testGoods);
		addMessage(redirectAttributes, "保存商品订单成功");
		return "redirect:"+Global.getAdminPath()+"/gog/testGoods/?repage";
	}

	@RequiresPermissions("gog:testGoods:edit")
	@RequestMapping(value = "delete")
	public String delete(TestGoods testGoods, RedirectAttributes redirectAttributes) {
		testGoodsService.delete(testGoods);
		addMessage(redirectAttributes, "删除商品订单成功");
		return "redirect:"+Global.getAdminPath()+"/gog/testGoods/?repage";
	}


}